<?php
/*
Autor: Marek Křivan
(c) 2009 
*/
if(intval($_SESSION['rank']) < 2){
	exit(WRONG_PERMISSIONS);
}
$id_tematu = 1 * $q[2];
$query = $GLOBALS['db']->query("SELECT forum,skupina,jmeno,zamknuto,dulezite FROM " . $GLOBALS['db_prefix'] ."forum_temata WHERE id = '$id_tematu';");
         while ($row = $query->fetch_array()) {
        $seo = ($GLOBALS['seo']) ? '' : 'index.php?q=';
        if(empty($row)) {
		 echo "<meta http-equiv=\"refresh\" content=\"1;".$GLOBALS['url'].$seo."forum/theme/".$id_fora."/1\" />"; echo("Toto fórum nebylo nalezeno! <a href=\"".$GLOBALS['url'].$seo."forum/theme/$id_fora/1\">Zpět</a>."); }
       
        $id_fora = $row[0];

if(isset($_POST['neodeslat_form'])) {

                echo "<meta http-equiv=\"refresh\" content=\"1;".$GLOBALS['url'].$seo."forum/dues/".$id_tematu."/1\" />";
        } 
if((isset($_POST['smazat_tema'])) && ($_SESSION['rank'] >= 2)) {
                        $smazani_id = 1 * $q[3];
                        $query = $GLOBALS['db']->query("DELETE FROM " . $GLOBALS['db_prefix'] ."forum_temata WHERE id = '$smazani_id' LIMIT 1");
                        $query = $GLOBALS['db']->query("DELETE FROM " . $GLOBALS['db_prefix'] ."forum_prispevky WHERE tema = '$smazani_id'");
                        $smazanych_prispevku = mysqli_affected_rows($db->conn);
                        $query = $GLOBALS['db']->query("UPDATE " . $GLOBALS['db_prefix'] ."forum_fora SET prispevku = prispevku - '$smazanych_prispevku', temat = temat - 1 WHERE id = '$id_fora'");
                        echo "<meta http-equiv=\"refresh\" content=\"1;".$GLOBALS['url']."index.php?q=forum/theme/".$id_fora."/1\" />";
                        exit();
                } else
                if((isset($_POST['smazat_prispevek']))) {
                        $smazani_id = 1 * $q[3];
                        $query = $GLOBALS['db']->query("DELETE FROM " . $GLOBALS['db_prefix'] ."forum_prispevky WHERE id = '$smazani_id' LIMIT 1");
                        $query = $GLOBALS['db']->query("UPDATE " . $GLOBALS['db_prefix'] ."forum_fora SET prispevku = prispevku - 1 WHERE id = '$id_fora'");
                        $query = $GLOBALS['db']->query("UPDATE " . $GLOBALS['db_prefix'] ."forum_temata SET odpovedi = odpovedi - 1 WHERE id = '$id_tematu'");
                        echo "<meta http-equiv=\"refresh\" content=\"1;".$GLOBALS['url']."index.php?q=forum/dues/".$id_tematu."/1\" />";
                        exit();
                } else
                if($_SESSION['rank'] >= 2) {
                        if($q[1] == "tema_delete") {
                                echo "<form action=\"".$GLOBALS['url']."index.php?q=forum/tema_delete/$q[2]/$q[3]\" method=\"post\"><fieldset><legend>Smazání tématu</legend><label>Opravdu si přejete toto téma smazat?</label><input type=\"submit\" value=\"Ano\" name=\"smazat_tema\" /> <input type=\"submit\" value=\"Ne\" name=\"neodeslat_form\" /><br /><br /></fieldset></form>";
                        } elseif($q[1] == "prispevek_delete") {
                                echo "<form action=\"".$GLOBALS['url']."index.php?q=forum/tema_delete/$q[2]/$q[3]\" method=\"post\"><fieldset><legend>Smazání příspěvku</legend><label>Opravdu si přejete tento příspěvek smazat?</label><input type=\"submit\" value=\"Ano\" name=\"smazat_prispevek\" /> <input type=\"submit\" value=\"Ne\" name=\"neodeslat_form\" /><br /><br /></fieldset></form>";
                        } else {
                                echo "<meta http-equiv=\"refresh\" content=\"1;".$GLOBALS['url']."index.php?q=forum/dues/".$id_tematu."/1\" />";
                                exit();
                        }
                } else {
                        echo "<meta http-equiv=\"refresh\" content=\"1;".$GLOBALS['url']."index.php?q=forum/dues/".$id_tematu."/1\" />";
                        exit();
                }
                }
                
?>

